package com.xps.and.yuntong.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xps.and.yuntong.Data.bean1.OrderList;
import com.xps.and.yuntong.R;
import com.xps.and.yuntong.Utils.TimeUtil;

import java.util.List;

/**
 * Created by Administrator on 2018/2/1.
 */

public class DingdanListAdpater extends BaseAdapter {


    private Context context;
    private LayoutInflater layoutInflater;
    private List<OrderList.ReturnBodyBean> data;

    public DingdanListAdpater(Context context, List<OrderList.ReturnBodyBean> data1) {
        this.context = context;
        this.data = data1;
        layoutInflater = layoutInflater.from(context);

    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.dingdan_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_dingdan_hao1 = (TextView) convertView.findViewById(R.id.tv_dingdan_hao1);
            viewHolder.tv_list_state = (TextView) convertView.findViewById(R.id.tv_list_state);
            viewHolder.tv_riqi = (TextView) convertView.findViewById(R.id.tv_riqi);
            viewHolder.tv_time_hour = (TextView) convertView.findViewById(R.id.tv_time_hour);
            viewHolder.tv_dizhi = (TextView) convertView.findViewById(R.id.tv_dizhi);
            viewHolder.tv_dizhi_zhongdian = (TextView) convertView.findViewById(R.id.tv_dizhi_zhongdian);
//                viewHolder.tvMenuName.setMovementMethod(ScrollingMovementMethod.getInstance());
            convertView.setTag(viewHolder);


        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_dingdan_hao1.setText(data.get(position).getOrder_sn());
        viewHolder.tv_dizhi.setText(data.get(position).getBegin_address());
        viewHolder.tv_dizhi_zhongdian.setText(data.get(position).getEnd_address());

        if (data.get(position).getOrder_state().equals("3")) {
            viewHolder.tv_list_state.setText("未完成");
            viewHolder.tv_time_hour.setText(TimeUtil.getStrTime2(data.get(position).getStart_time()));

        } else if (data.get(position).getOrder_state().equals("4")) {
            viewHolder.tv_list_state.setText("未完成");
            viewHolder.tv_time_hour.setText(TimeUtil.getStrTime2(data.get(position).getStart_time()));

        } else if (data.get(position).getOrder_state().equals("5")) {
            viewHolder.tv_list_state.setText("行驶中");
            viewHolder.tv_time_hour.setText(TimeUtil.getStrTime2(data.get(position).getStart_time()));


        } else if (data.get(position).getOrder_state().equals("6")) {
            viewHolder.tv_list_state.setText("已完成");
            viewHolder.tv_time_hour.setText(TimeUtil.getStrTime2(data.get(position).getEnd_time()));

        }


//            viewHolder.tv_shouru.setText(data.get(position).getTitle().trim());

        return convertView;
    }


    class ViewHolder {

        TextView tv_dingdan_hao1;
        TextView tv_list_state;
        TextView tv_riqi;
        TextView tv_time_hour;
        TextView tv_dizhi;
        TextView tv_dizhi_zhongdian;


    }


}

